home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11819 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: tank.news.pipex.net!pipex!iol!not-for-mail
  2. From: goyra@iol.ie (David Byrden)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Object constuction in function call.
  5. Date: 16 Mar 1996 11:25:56 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4ie8g4$h9j@nuacht.iol.ie>
  8. References: <4icmqh$8g6@insosf1.netins.net> <4ie16n$pc1@sam.inforamp.net>
  9. NNTP-Posting-Host: joyce.iol.ie
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Randy Charles Morin (rmorin@inforamp.net) wrote:
  13. : In article <4icmqh$8g6@insosf1.netins.net>,
  14. :    hhowe@trgnet.com (Harold Howe) wrote:
  15. : >class TCorners
  16. : >  {
  17. : >  public:
  18. : >    int w,x,y,z;
  19. : >    TCorners( int a, int b, int c, int d) 
  20. : >      { w=a;   x=b; y=c;  z=d;}
  21. : >  } 
  22. : >
  23. : >  display_coordinates(TCorners(1,1,20,10));
  24. : The TCorners that you declare in main() are destroyed when you exit main.  
  25. : Thus at the end of your program you have 0 objects.  Here's a procedure look 
  26. : at what is happening.
  27. : int main(void)
  28. : {
  29. :     construct TCorners
  30. :     display TCorners
  31. :     construct TCorners
  32. :     display TCorners
  33. :     construct TCorners
  34. :     display TCorners
  35. :     destroy TCorners
  36. :     destroy TCorners
  37. :     destroy TCorners
  38. : };
  39. : when the TCorners lose scope, then the destroy themselves.
  40. : Agrivar
  41.  
  42. Well, unfortunately, this explanation is wrong. The TCorners created
  43. as function parameters are "temporaries" and they have NO scope, for
  44. the simple reason that they have no names. Their lifetime is defined to
  45. end when you finish the STATEMENT in which they were created, not when 
  46. you leave the current block.
  47.  
  48.                                       David
  49.  
  50.